package com.anttribe.components.db.sql.statement;

import java.util.HashMap;
import java.util.Map;

import org.apache.commons.text.StringSubstitutor;

import com.anttribe.components.db.sql.stereotype.DDLSqlStatement;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

/**
 * @author zhaoyong
 * @date 2022/11/21 0021
 */
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
public class DropTableSqlStatement extends AbstractSqlStatement implements DDLSqlStatement {
    
    private static final String SQL_TEMPLATE = "DROP TABLE IF EXISTS ${tableName}";
    
    /**
     * sql语句模板
     */
    private String sqlTemplate = SQL_TEMPLATE;
    
    /**
     * 表名
     */
    private String tableName;
    
    @Override
    public String generateSqlInner() {
        StringSubstitutor StringSubstitutor = new StringSubstitutor(this.buildValueMap());
        // 替换变量
        return StringSubstitutor.replace(sqlTemplate);
    }
    
    /**
     * 构造ValueMap
     *
     * @return Map<String, Object>
     */
    private Map<String, Object> buildValueMap() {
        Map<String, Object> valueMap = new HashMap<>();
        valueMap.put("tableName", this.tableName);
        return valueMap;
    }
    
}
